<template>
  <div class="loginphones-page">
    <div class="headerBox">
      <van-nav-bar
        title="用户名登录"
        left-arrow
        @click-left="onClickLeft"
      ></van-nav-bar>
    </div>
    <div class="input_box">
      <div class="samll_box">
        <i class="icon user"></i>
        <input type="text" v-model="username" placeholder="请输入用户名" placeholder-style="color:#D6D5D5">
        <span class="clear" @click="username=''"></span>
      </div>
      <div class="samll_box">
        <i class="icon pass"></i>
        <input type="password" v-model="pass" placeholder="请输入密码">
      </div>
      <div class="forget" @click="goForget">忘记密码？</div>
    </div>
    <div class="footer" v-show="isOriginHei">
      <span v-if="!type">登录</span>
      <span v-else class="sub" @click="handleSubmit">登录</span>
    </div>
  </div>
</template>

<script>
import positionBtn from "../positionBtn.js";
export default {
  mixins: [positionBtn],
  data() {
    return {
      type: false,
      username: "",
      pass: "",
      date:''
    };
  },
  watch: {
    pass(val) {
      if (val.length>0) {
        this.type = true
      } else {
        this.type = false
      }
    },
  },
  created() {
    sessionStorage.clear();
    localStorage.removeItem('userInfor');;
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    goForget() {
      setTimeout(() => {
        this.$router.push({name: 'forget'})
      }, 200);
    },
    async handleSubmit() {
      if (!this.username) {
        this.$toast("请输入用户名");
        return false;
      }
      if (!this.pass) {
        this.$toast("请输入密码");
        return false;
      }
      let ruleForm = {
        username: this.username,
        pass: this.pass
      }
      let res = await this.$http.login({...ruleForm});
      if (res) {
        let userInfor = res.addInfo;
        userInfor.token = res.data;
        localStorage.setItem("userInfor", JSON.stringify(userInfor));
        setTimeout(() => {
          this.$router.push({path:'/'})
        });
      }
    },
  },
};
</script>

<style scoped>
.loginphones-page {
  background: #fff;
  height: 100vh;
}
.input_box {
  padding: 1rem .5rem;
}
.samll_box{
  height: 1rem;
  line-height: 1rem;
  border-bottom: .02rem solid #D6D5D5;
  margin-bottom: .4rem;
}
.samll_box > input{
  height: 100%;
  width: 5rem;
  border: none;
  font-size: .35rem;
}
.icon,.clear{
  display: inline-block;
  width: .48rem;
  height: .48rem;
  position: relative;
  top: .1rem;
  margin-right: .2rem;
}
.user{
  background: url('../../assets/img/login/icon_geren.png') no-repeat;
  background-size: 100% 100%;
}
.pass{
  background: url('../../assets/img/login/icon_mima.png') no-repeat;
  background-size: 100% 100%;
}
.clear{
  background: url('../../assets/img/login/icon_shanch.png') no-repeat;
  background-size: 100% 100%;
}
.forget{
  float: right;
  font-size: .29rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #000000;
}
.footer{
  width: 100%;
  position: fixed;
  padding: 0 .5rem;
  bottom: 2.2rem;
}
.footer > span{
  width: 100%;
  display: inline-block;
  height: .94rem;
  background: #00C8E7;
  line-height: .94rem;
  text-align: center;
  color: #fff;
  border-radius: .47rem;
  font-size: .34rem;
  opacity: .4;
}
.footer span.sub{
  opacity: 1;
}
</style>
